主题
寻路算法 - PathPlanning
函数简介
提供二值化地图自动寻路功能,白色为可通行区域,黑色为障碍物,在指定起点和终点之间寻找最优路径。当起点和终点在不可通信区域时会自动吸附到最近的可通行区域
接口名称
PathPlanningDLL调用
c
long PathPlanning(long instance, long image, int startX, int startY, int endX, int endY, double potentialRadius, double searchRadius);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| image | 长整数型 | 二值化图像句柄。 |
| startX | 整数型 | 起点X坐标。 |
| startY | 整数型 | 起点Y坐标。 |
| endX | 整数型 | 终点X坐标。 |
| endY | 整数型 | 终点Y坐标。 |
| potentialRadius | 双精度浮点数 | 势场半径。半径小:势场计算更"局部",每个点主要考虑附近几格的距离;半径大:势场计算更"全局",路径更平滑但计算量更大。 |
| searchRadius | 双精度浮点数 | 搜索半径,限制搜索范围。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
long image = ola.LoadImage("maps/path_map.png");
if (image != 0) {
auto path = ola.PathPlanning(image, 10, 10, 500, 400, 3.0, 50.0);
ola.FreeImage(image);
}csharp
using OLAPlug;
var ola = new OLAPlugServer();
long image = ola.LoadImage("maps/path_map.png");
if (image != 0)
{
var path = ola.PathPlanning(image, 10, 10, 500, 400, 3.0, 50.0);
ola.FreeImage(image);
}python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
image = ola.LoadImage("maps/path_map.png")
if image != 0:
path = ola.PathPlanning(image, 10, 10, 500, 400, 3.0, 50.0)
ola.FreeImage(image)java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
long image = ola.LoadImage("maps/path_map.png");
if (image != 0) {
var path = ola.PathPlanning(image, 10, 10, 500, 400, 3.0, 50.0);
ola.FreeImage(image);
}cpp
var ola = com("OlaPlug.OlaSoft")
var image = ola.LoadImage("maps/path_map.png")
if(image) {
ola.PathPlanning(image, 10, 10, 500, 400, 3.0, 50.0);
ola.FreeImage(image)
}vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
image = ola.LoadImage("maps/path_map.png")
If image <> 0 Then
ola.PathPlanning(image, 10, 10, 500, 400, 3.0, 50.0);
ola.FreeImage(image)
End Iftext
.局部变量 ola, OLAPlug
ola.创建 ()
image = ola.LoadImage ("maps/path_map.png")
.如果真 (image ≠ 0)
ola.PathPlanning(image, 10, 10, 500, 400, 3.0, 50.0);
ola.FreeImage (image)
.如果真结束aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var image = ola.LoadImage("maps/path_map.png");
if(image){
ola.PathPlanning(image, 10, 10, 500, 400, 3.0, 50.0);
ola.FreeImage(image);
}text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
长整数 image = ola.LoadImage("maps/path_map.png")
如果真 (image ≠ 0)
{
ola.PathPlanning(image, 10, 10, 500, 400, 3.0, 50.0);
ola.FreeImage(image)
}cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
long image = ola.LoadImage("maps/path_map.png");
if (image != 0) {
ola.PathPlanning(image, 10, 10, 500, 400, 3.0, 50.0);
ola.FreeImage(image);
}原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
long image = LoadImage(instance, "maps/path_map.png");
if (image != 0) {
auto path = ola.PathPlanning(image, 10, 10, 500, 400, 3.0, 50.0);
FreeImage(instance, image);
}csharp
using System.Runtime.InteropServices;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
long instance = CreateCOLAPlugInterFace();
long image = LoadImage(instance, "maps/path_map.png");
if (image != 0) {
var path = ola.PathPlanning(image, 10, 10, 500, 400, 3.0, 50.0);
FreeImage(instance, image);
}python
from ctypes import CDLL, c_int, c_int64
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
image = ola.LoadImage(instance, b"maps/path_map.png")
if image:
path = ola.PathPlanning(image, 10, 10, 500, 400, 3.0, 50.0)
ola.FreeImage(instance, image)返回值
| 返回值 | 说明 |
|---|---|
| (返回值) | 返回路径规划结果字符串指针,格式为JSON:。 |
json
[
{"x": 1, "y": 2},
{"x": 2, "y": 1}
]| 字段名 | 类型 | 说明 |
|---|---|---|
| x | 整数 | x 字段值。 |
| y | 整数 | y 字段值。 |
返回的字符串指针需要调用 FreeStringPtr 释放内存。
注意事项
| 项目 | 说明 |
|---|---|
| 路径 | potentialRadius、searchRadius 为负数时只返回JPS寻路数据,不做路径优化。 |
| 输入的图像为二值化图像 | 确保输入的图像为二值化图像,白色区域为可通行,黑色区域为障碍物。 |
| 起点和终点坐标必须在图像范围内 | 起点和终点坐标必须在图像范围内。 |
